﻿using System;
using Enyim.Caching;
using Ayatta.Contract;
using System.Web.Mvc;
using System.Web.WebPages;
using Web.Base.Extensions;
using Web.Manage.Controllers;
using Ayatta.Common.Extensions;
using Web.Manage.Areas.User.Models;

namespace Web.Manage.Areas.User.Controllers
{
    public class HomeController : AdminBaseController
    {
        public HomeController(ILogService logService, IBaseService baseService, IExtraService extraService, IStoreService storeService, IOrderService orderService, IGameService gameService, IAuctionService auctionService, IPassportService passportService, IPaymentService paymentService, IMemcachedClient memcachedClient)
            : base(logService, baseService, extraService, storeService, orderService, gameService, auctionService, passportService, paymentService, memcachedClient)
        {
        }
        /// <summary>
        /// 用户列表
        /// </summary>
        /// <param name="page">当前页</param>
        /// <param name="size">分页大小</param>
        /// <param name="keyword">Id/Guid/用户名</param>
        /// <param name="status">状态</param>
        /// <returns></returns>
        public ActionResult Index(int page = 1, int size = 20, string keyword = null, bool? status = null)
        {
            Guid guid;
            var model = new HomeControllerModel.Index();
            model.Status = status;
            model.Keyword = keyword;
            if (!keyword.IsMobile() && keyword.AsInt(0) > 0)
            {
                var id = keyword.AsInt();
                model.Users = PassportService.GetPagedUsers(page, size, id, null, null, status).ToPagedList(page, size);
            }
            else if (Guid.TryParse(keyword, out guid))
            {
                model.Users = PassportService.GetPagedUsers(page, size, null, guid.ToString(), null, status).ToPagedList(page, size);
            }
            else
            {
                model.Users = PassportService.GetPagedUsers(page, size, null, null, keyword, status).ToPagedList(page, size);
            }
            return PartialView(model);
        }

        /// <summary>
        /// 用户详细信息
        /// </summary>
        /// <param name="param">用户Id</param>
        /// <returns></returns>
        public ActionResult Detail(int param)
        {
            var model = new HomeControllerModel.Detail();
            model.User = PassportService.GetUser(param, true, true);
            return PartialView(model);
        }
    }
}
